from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

# 1.登录
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("http://129.211.129.101:9007/index.php?m=user&c=public&a=login")
driver.find_element(By.ID, "username").send_keys("lllljl")
driver.find_element(By.ID, "password").send_keys("bj0304BJA@")
driver.find_element(By.ID, "password").submit()

# 2.进入商城购物页
driver.find_element(By.LINK_TEXT, '进入商城购物').click()
# 3.搜索
driver.find_element(By.CLASS_NAME, 'input_ss').send_keys("iphone")
driver.find_element(By.CLASS_NAME, 'btn1').click()
# 4.点击商品图片
driver.find_element(By.CLASS_NAME, 'shop_01-imgbox').click()
# 5.把选择的商品加入购物车
new_window = driver.window_handles[-1]
driver.switch_to.window(new_window)
driver.find_element(By.ID, 'joinCarButton').click()

# 6.去购物车结算
driver.find_element(By.CLASS_NAME, 'shopCar_T_span3').click()
# 7.点击结算
driver.find_element(By.CSS_SELECTOR, '.shopCar_btn_03.fl').click()
# 8.添加地址
driver.find_element(By.CLASS_NAME, 'add-address').click()
driver.find_element(By.NAME, 'address[address_name]').send_keys('lllljl')
driver.find_element(By.NAME, 'address[mobile]').send_keys('13555555555')
area = driver.find_element(By.ID, 'add-new-area-select')
Select(area).select_by_visible_text('广东省')
city = driver.find_elements(By.CSS_SELECTOR, '.add-new-area-select')[1]
Select(city).select_by_visible_text('广州市')
district = driver.find_elements(By.TAG_NAME, 'select')[2]
Select(district).select_by_visible_text('番禺区')

driver.find_element(By.NAME, 'address[address]').send_keys("曾边锦溪苑")
driver.find_element(By.NAME, 'address[zipcode]').send_keys("16000")
driver.find_element(By.CLASS_NAME, 'aui_state_highlight').click()
